package com.lvmama.java.rhino.etl.main;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.lvmama.java.rhino.spark.core.ICallback;
import com.lvmama.java.rhino.spark.core.ISparkExecuting;
import com.lvmama.java.rhino.spark.utils.ZookeeperUtils;

import common.Logger;

/**
 * Java版本Spark程序入口
 * @author wxliyong
 * @date 2016-4-16 19:10:44
 */
public class Main {
	private static String processer = null;
	private static final Logger LOGGER = Logger.getLogger(Main.class);
	
	public static void main(String[] args) {
		if (args.length == 0) {
			System.err.println("参数不足，无法启动！");
			LOGGER.error("参数不足，无法启动！");
			return;
		}
		processer = args[0];
		final ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/spring-rhino-etl-beans.xml");
		Object obj = ctx.getBean(processer);
		if(obj instanceof ISparkExecuting) {
			ISparkExecuting sparkExecuting = (ISparkExecuting) obj;
			sparkExecuting.run(args, new ICallback() {
				@Override
				public void call(Object obj) {
					ctx.close();
					ZookeeperUtils.getInstance().close();
					String result = "Spark Streaming: " + processer + " shutdown";
					System.out.println(result);
					LOGGER.error(result);
					System.exit(0);
				}
			});
		}
	}
}
